﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LynxWiki.DomainModel
{
    public class SearchData
    {
        public string ID { get; set; } /* ID includes TopicName and WikiDir in the index */
        public string TopicName { get; set; }
        public string WikiDir { get; set; }
        public string Creator { get; set; }
        public DateTime CreatedOn { get; set; }
        public string WikiText { get; set; }
        public string Tags { get; set; }  /* each tag is space separated */
        public string Type { get; set; }

        public SearchData() { }

        public SearchData(TopicVersion tv, string type)
        {
            ID = type + ":" + tv.WikiDir.Replace("\\","/") + "." + tv.TopicName;
            TopicName = tv.TopicName;
            WikiDir = tv.WikiDir.Replace("\\","/");
            Creator = tv.Creator;
            CreatedOn = tv.CreatedOn;
            WikiText = tv.WikiText;

            string tempTags = string.Empty;
            if (tv.Tags != null) {
                foreach (string t in tv.Tags) {
                    if (!string.IsNullOrEmpty(tempTags)) tempTags += " ";
                    tempTags += t;
                }
            }
            Tags = tempTags;

            Type = type;
        }
    }
}
